package com.youpai.platform.vulture.service.util;

import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Lists;
import com.youpai.platform.vulture.common.entity.AccessMessage;
import com.youpai.platform.vulture.common.entity.Header;
import com.youpai.platform.vulture.common.enums.HeaderTypeEnum;
import com.youpai.platform.vulture.common.enums.MsgFlagEnum;
import com.youpai.platform.vulture.common.enums.ServerCommandEnum;

import java.util.List;

/**
 * @time: 2022/8/3 6:58 下午
 * @author: welles
 * @description: 消息工具包
 */
public class MessageUtil {

    /**
     * 构建服务端单聊消息
     *
     * @param body 消息体
     * @return AccessMessage
     */
    public static AccessMessage buildC2CAccessMessage(String body,Integer cmd) {
        List<Header> headerList = buildC2CHeaderList(cmd);
        AccessMessage accessMessage = new AccessMessage();
        accessMessage.setFlag(MsgFlagEnum.ORDINARY_MSG.flag);
        accessMessage.setHeaderList(headerList);
        accessMessage.setBody(body);
        return accessMessage;
    }

    private static List<Header> buildC2CHeaderList(Integer cmd) {
        Header header = new Header()
                .setHeaderType(HeaderTypeEnum.COMMAND.type)
                .setHeaderValue(cmd);
        return Lists.newArrayList(header);
    }
}
